package com.wd.mylibrary_square.view.activity

import com.wd.mylibrary_base.base.BaseActivity
import com.wd.mylibrary_base.utils.MyApp
import com.wd.mylibrary_square.R
import com.wd.mylibrary_square.databinding.ActivityZodiacBinding
import com.wd.mylibrary_square.view.adapter.ZodiacAdapter
import com.wd.mylibrary_square.viewmodel.ZodiacViewModel


class ZodiacActivity : BaseActivity<ZodiacViewModel,ActivityZodiacBinding>(R.layout.activity_zodiac) {

    override fun initView() {
        var userId = MyApp.sp.getInt("userId", 0)
        var sessionId = MyApp.sp.getString("sessionId", "").toString()

        viewModel.getConstellationData(userId,sessionId,20,10)

        //返回 销毁页面
        dataBinding.back.setOnClickListener({
            finish()
        })


    }

    override fun dataObserve() {
        var userId = MyApp.sp.getInt("userId", 0)
        var sessionId = MyApp.sp.getString("sessionId", "").toString()


        viewModel.constellationData.observe(this,{
            if(it.result!=null){
                val adapter = ZodiacAdapter(this, it.result)
                dataBinding.sv.adapter=adapter


                //接口回调  调用接口
                adapter.setOnGuanZhu(object :ZodiacAdapter.Guanzhu{
                    override fun attention(attention: String, index: Int) {
                        if(index==1){
                            if(index==1){
                                viewModel.getAttentionData(userId,sessionId,attention)
//                                Toast.makeText(this, "关注成功", Toast.LENGTH_SHORT).show()
                            }else{
                                viewModel.getCancelAttentionData(userId,sessionId,attention.toInt())
//                                Toast.makeText(this, "取消关注成功", Toast.LENGTH_SHORT).show()
                            }
                        }
                    }

                })
            }


        })

    }

}